import pymysql.cursors

# 连接数据库
conn = pymysql.Connect(
    host='47.94.130.233',
    port=3306,
    user='root',
    passwd='123456',
    db='training',
    charset='utf8',
)
# 获取游标
my_cursor = conn.cursor()
# 准备SQL
sql = 'delete from emp where id = %s'
# 准备插入的数据
values = (2,)

try:
    # 执行SQL
    my_cursor.execute(sql, values)
    # 手动提交事务
    conn.commit()
    print('删除', my_cursor.rowcount, '条数据')
except Exception as e:
    # 事务回滚
    conn.rollback()
finally:
    # 关闭连接
    conn.close()

